package com.prime.tutorial.moviestore.view.logistics;

import com.prime.tutorial.moviestore.domain.Device;
import com.prime.tutorial.moviestore.service.logistics.LogisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.faces.event.ActionEvent;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * Users: me
 * Date: 14 бер 2010
 * Time: 19:04:30
 * @author iryna.masyuk
 */

@Component("listDevicesAvailableInstallation")
@Scope("request")
public class ListDevicesAvailableInstallation {
    private LogisticsService logisticsService;
     private Device deviceSelected;
    private Device[] arrayDeviceSelected;

     @Autowired
     public ListDevicesAvailableInstallation(LogisticsService logisticsService) {
        this.logisticsService = logisticsService;
     }
     public List getDevicesAvailableInstallation(){
         return logisticsService.getDevicesAvailableInstallation();
     }
    public void send(ActionEvent e){
//        logisticsService.setApproved(deviceSelected);
//        deviceSelected=null;
      for(int i=0;i<getArrayDeviceSelected().length;i++) {
          logisticsService.setApproved(getArrayDeviceSelected()[i]);
      }
        setArrayDeviceSelected(null);
    }
    //-----------------------------------------getters&setters
    public Device getDeviceSelected() {
        return deviceSelected;
    }

    public void setDeviceSelected(Device deviceSelected) {
        this.deviceSelected = deviceSelected;
    }

    public Device[] getArrayDeviceSelected() {
        return arrayDeviceSelected;
    }

    public void setArrayDeviceSelected(Device[] arrayDeviceSelected) {
        this.arrayDeviceSelected = arrayDeviceSelected;
    }
}
